package javabasics.netty.login.client.console;

import io.netty.channel.Channel;
import javabasics.netty.login.protocol.request.LoginRequestPacket;

import java.util.Scanner;

/**
 * @Author suxiaoxiao
 * @Date 2019/9/19 23:08
 * @Version 1.0
 */
public class LoginConsoleCommand implements ConsoleCommand {

    @Override
    public void exec(Scanner scanner, Channel channel) {
        LoginRequestPacket loginRequestPacket = new LoginRequestPacket();

        System.out.println("输入用户名登录：");
        loginRequestPacket.setUserName(scanner.nextLine());
        loginRequestPacket.setPassword("pwd");

        // 发送登录数据包
        channel.writeAndFlush(loginRequestPacket);
        waitForLoginResponse();
    }

    private void waitForLoginResponse() {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
